<?php 
namespace Home\Controller;
use Think\Controller;
/**
* 注册
*/
class RegController extends CommonController
{
	
	public function index()
	{
		$question= D('vercode')->getOne();
		$this->assign('question',$question);
		$this->display();
	}
	public function check()
	{  //前端验证
		
		$data=$_POST;
		//邮箱
		$rec=D('user')->where("email='$data[email]'")->select();
		if ($rec) {
			$arr=array(
				'error'=>'1',
				'info' =>'邮箱已注册，请换一个邮箱',
				);
			echo json_encode($arr);
			exit;
		}
		//呢称
		$rec=D('user')->where("nikename='$data[nikename]'")->select();
		if ($rec) {
			$arr=array(
				'error'=>'2',
				'info' =>'昵称已存在，请换一个',
				);
			echo json_encode($arr);
			exit;
		}
		//密码
		$preg='/^\w{6,16}$/';
		$c=preg_match($preg,$data['password']);
		if (!$c) {
			$arr=array(
				'error'=>'3',
				'info' =>'密码格式不正确',
				);
			echo json_encode($arr);
			exit;
		}
		//密码对比
		if (!$data['password']==$data['repass']) {
			$arr=array(
				'error'=>'4',
				'info' =>'两次密码不一样',
				);
			echo json_encode($arr);
			exit;
		}
		//人工验证
		$this->checkVercode();	
		$data['create_time']=time();
		$data['password']=md5($data['password']);
		$data['face']='Uploads/1.jpg';

		$data['create_ip']=get_client_ip();
		M('user')->data($data)->add();
		$arr=array(
				'error'=>'0',
				'info' =>'注册成功',
				);
		echo json_encode($arr);
		 // header("Location:{:U('home/enter/index')}");
	}
}

 ?>